package com.cyam.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.cyam.service.ArticleService;
import com.cyam.util.Pager;

@Controller
@RequestMapping("/blog")
public class LoginController {
	
	@Resource
	private ArticleService articleService;
	
	private final String USERNAME = "王文强"; 
	private final String PASSWORD = "WANG123456"; 

	@RequestMapping("/login")
	public ModelAndView mvLogin() {
		return new ModelAndView("/system/login");
	}
	
	
	
	@RequestMapping("/loginin")
	public ModelAndView LoginIn(Model model,@RequestParam("username") String username,
			@RequestParam("password")String password,HttpServletRequest request) throws Exception {
		HttpSession session = request.getSession();
		ModelAndView mv = new ModelAndView();
		if (USERNAME.equals(username) || PASSWORD.equals(password)) {
			session.setAttribute("username", username);
			Pager pages = articleService.countPager3(null,1, 12);
			model.addAttribute("pages", pages);
			mv.setViewName("/system/index");
		}else {
			mv.setViewName("/system/login");
		}
		return mv;
	}
	
}
